home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / demo / mag / hLA-AP15.lha / hLA-AP15 / bonus / zdroj.lha / halda.asc next >
Text File  |  2000-05-01  |  1KB  |  82 lines

  1. N=200
  2. Dim halda(N)
  3.  
  4.  
  5.  
  6. For a=1 To N
  7.   halda(a)=Int(Rnd(100))
  8. Next a
  9.  
  10. NPrint "Nestridene pole:"
  11. Gosub vypis
  12. Gosub makeheap
  13. NPrint "Halda:"
  14. Gosub vypis
  15. Gosub setrid
  16. NPrint "Setridene pole:"
  17. Gosub vypis
  18.  
  19. d$=Edit$(1)
  20. End
  21.  
  22. setrid
  23. For a=1 To N-1
  24.   Gosub vypustmin
  25.   halda(pocet+1)=minimum
  26. Next a
  27. Return
  28.  
  29. vypustmin
  30.   minimum=halda(1)
  31.   X=halda(pocet)
  32.   pocet=pocet-1
  33.   otec=1
  34.   pokracuj=True
  35.   While pokracuj
  36.     syn=2*otec
  37.     If syn<=pocet
  38.       If syn<pocet
  39.         If halda(syn)>halda(syn+1) Then syn=syn+1
  40.       EndIf
  41.       If X>halda(syn)
  42.         halda(otec)=halda(syn)
  43.         otec=syn
  44.       Else
  45.         pokracuj=False
  46.       EndIf
  47.     Else
  48.       pokracuj=False
  49.     EndIf
  50.   End While
  51. halda(otec)=X
  52. Return
  53.  
  54. makeheap
  55.   For pocet=2 To N
  56.   syn=pocet
  57.   X=halda(pocet)
  58.   pokracovat=True
  59.   While pokracovat
  60.     otec=Int(syn/2)
  61.     If halda(otec)<X
  62.       pokracovat=False
  63.     Else
  64.       halda(syn)=halda(otec)
  65.       syn=otec
  66.       If syn=1 Then pokracovat=False
  67.     EndIf
  68.   End While
  69.   halda(syn)=X
  70.   Next pocet
  71.   pocet=50
  72. Return
  73.  
  74. vypis
  75. For a=0 To Int(N/10)-1
  76.   For b=1 To 10
  77.     Print halda(a*10+b),"  "
  78.   Next b
  79.   NPrint ""
  80. Next a
  81. Return
  82.